﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SqlCEUpgrade
{
    class PropertyGenerator
    {
        public static void Generate()
        {
            String file = "D:\\generate.txt";
            List<String> fields = new List<String>();
            fields.Add("VAAgencyFund");
            fields.Add("VABank");
            fields.Add("VABankList");
            fields.Add("VAClaimedValue");
            fields.Add("VAInsuranceFee");
            fields.Add("VAInsuranceFeeWindow");
            fields.Add("VAReceiptFee");
            fields.Add("VAReceiptTypeReceipt");
            fields.Add("VAReceiptTypeStamp");
            fields.Add("VAReceiptTypeIDNum");
            fields.Add("VADeliveryFee");
            fields.Add("VADeliveryFeeWindow");
            fields.Add("VAForwardFee");
            fields.Add("VAForwardAddr");
            fields.Add("VACollaborativeLogistics");
            fields.Add("VAAdvance");
            fields.Add("VAPrepay");
            fields.Add("BillComment");
            
            Generate(fields, file);
        }
        public static void Generate(List<String> fields,String filePath)
        {
            StringBuilder sBuider = new StringBuilder();

            foreach(String field in fields)
            {
                String fieldName = "_"+field;
                String propertyName = field;
                sBuider.AppendLine(String.Format("private String {0};",fieldName));
                sBuider.AppendLine(String.Format("public String {0}",propertyName));
                sBuider.AppendLine("{");
                sBuider.AppendLine(String.Format("  get {{ return {0}; }}",fieldName));
                sBuider.AppendLine("    set");
                sBuider.AppendLine("    {");
                sBuider.AppendLine(String.Format("        if({0} !=value)",fieldName));
                sBuider.AppendLine("            {");
                sBuider.AppendLine(String.Format("                {0} = value;",fieldName));
                sBuider.AppendLine(String.Format("                RaisePropertyChanged(\"{0}\");",propertyName));
                sBuider.AppendLine("            }");
                sBuider.AppendLine("    }");
                sBuider.AppendLine("}");
                sBuider.AppendLine();
            }

            File.WriteAllText(filePath, sBuider.ToString());
        }
    }
}
